package com.ymatou.iapi.godmch.testcase;

import groovy.lang.BenchmarkInterceptor;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.internal.runners.TestMethod;

import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.applyAgentBean;
import com.ymatou.iapi.godmch.parameter.createDepotBean;
import com.ymatou.iapi.godmch.parameter.createIndepMchBean;
import com.ymatou.iapi.godmch.service.applyAgentCall;
import com.ymatou.iapi.godmch.service.createDepotCall;
import com.ymatou.iapi.godmch.service.createIndepMchCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.mapping.godmch.mch_depot_infoMapper;
import com.ymttest.database.mapping.godmch.mch_depot_infoSqlProvider;
import com.ymttest.database.model.godmch.mch_depot_info;
import com.ymttest.database.model.godmch.mch_depot_infoExample;
import com.ymttest.database.sqlwapper.godmch.mch_depot_infoWapper;
import com.ymttest.utils.TestDataManager;
/**
*新增仓库信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_createDepot{
	private static createDepotBean bean;
	private static createDepotCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("新增仓库信息");
	}

	@Before
	public void caseUp() {
		bean=new createDepotBean();
		call=new createDepotCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	private void check_verify(Integer mchId) throws InterruptedException {
		
		Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
		mch_depot_infoWapper depotWapper=new mch_depot_infoWapper();
		mch_depot_infoExample example=new mch_depot_infoExample();
		example.createCriteria().andMchIdEqualTo(bean.getMchId());
        List<mch_depot_info> lst=depotWapper.selectByExample(example);
        
        Logger.verifyEquals(1, lst.size(), "验证新增1条");
        int count=1;
        for(mch_depot_info depot:lst)
        {
        	Logger.verifyEquals(bean.getDepotTitle(), depot.getDepotTitle(), "验证第"+count+"个数据库字段DepotTitle与传入的是否一致");
        	Logger.verifyEquals(bean.getRemark(), depot.getRemark(), "验证第"+count+"个数据库字段Remark与传入的是否一致");
        	Logger.verifyEquals(0, depot.getDepotStatus(), "验证第"+count+"个数据库字段DepotStatus=0");
        	//新增 20200619
        	Logger.verifyEquals(bean.getBuyerTitle()==null?"":bean.getBuyerTitle(), depot.getBuyerTitle(), "验证第"+count+"个数据库字段BuyerTitle与传入的是否一致");
        	Logger.verifyEquals(bean.getPicUrl()==null?"":bean.getPicUrl(), depot.getPicUrl(), "验证第"+count+"个数据库字段PicUrl与传入的是否一致");
        	
        }
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_createDepot_001() {
		Logger.start(true,"新增仓库信息-验证渠道角色");
		try {
			
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			bean.setMchId(mchId);
			bean.setDepotTitle("仓库名称1q_"+TestDataManager.getRandomIntNum(5));
			bean.setRemark("新增仓库信息_"+TestDataManager.getRandomIntNum(5));
			bean.setBuyerTitle("买家端显示名称_"+TestDataManager.getRandomNum(5));
			bean.setPicUrl("http://www.baidu.com_"+TestDataManager.getRandomNum(5)+".jpg");
			call.setData(bean);
			call.callService();			
			
			check_verify(mchId);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_createDepot_001_1() {
		Logger.start(true,"新增仓库信息-验证同意商户新增2条");
		try {
			
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			bean.setMchId(mchId);
			bean.setDepotTitle("仓库名称1q_"+TestDataManager.getRandomIntNum(5));
			bean.setRemark("新增仓库信息_"+TestDataManager.getRandomIntNum(5));
			bean.setBuyerTitle("买家端显示名称_"+TestDataManager.getRandomNum(5));
			bean.setPicUrl("http://www.baidu.com_"+TestDataManager.getRandomNum(5)+".jpg");
			call.setData(bean);
			call.callService();			
			check_verify(mchId);
			
			bean.setMchId(mchId);
			bean.setDepotTitle("仓库名称1q_"+TestDataManager.getRandomIntNum(5));
			bean.setRemark("新增仓库信息_"+TestDataManager.getRandomIntNum(5));
			bean.setBuyerTitle("买家端显示名称_"+TestDataManager.getRandomNum(5));
			bean.setPicUrl("http://www.baidu.com_"+TestDataManager.getRandomNum(5)+".jpg");
			call.setData(bean);
			call.callService();	
			
			mch_depot_infoWapper depotWapper=new mch_depot_infoWapper();
			mch_depot_infoExample example=new mch_depot_infoExample();
			example.createCriteria().andMchIdEqualTo(mchId);
			List<mch_depot_info>  lst=depotWapper.selectByExample(example);
	        mch_depot_info depot=lst.get(1);
		    Logger.verifyEquals(2, lst.size(), "验证新增2条");   
        	Logger.verifyEquals(bean.getDepotTitle(), depot.getDepotTitle(), "验证第2个数据库字段DepotTitle与传入的是否一致");
        	Logger.verifyEquals(bean.getRemark(), depot.getRemark(), "验证第2个数据库字段Remark与传入的是否一致");
        	Logger.verifyEquals(0, depot.getDepotStatus(), "验证第2个数据库字段DepotStatus=0");
        	
        	//新增 20200619
        	Logger.verifyEquals(bean.getBuyerTitle()==null?"":bean.getBuyerTitle(), depot.getBuyerTitle(), "验证第2个数据库字段BuyerTitle与传入的是否一致");
        	Logger.verifyEquals(bean.getPicUrl()==null?"":bean.getPicUrl(), depot.getPicUrl(), "验证第2个数据库字段PicUrl与传入的是否一致");
		        
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_createDepot_002() {
		Logger.start(true,"新增仓库信息-验证代理角色");
		try {
			
			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			Integer agentid = GodmchManageCallService.CreateSellerMch(code);
			bean.setMchId(agentid);
			bean.setDepotTitle("仓库名称1q_"+TestDataManager.getRandomIntNum(5));
			bean.setRemark("新增仓库信息_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
	
			check_verify(agentid);		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_createDepot_002_1() {
		Logger.start(true,"新增仓库信息-验证独立商户");
		try {
			
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createIndepMchCall= GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
	        applyAgentCall applyAgentCall= GodmchManageCallService.applyAndapproveAgent(createIndepMchCall.getmchId());

			bean.setMchId(createIndepMchCall.getmchId());
			bean.setDepotTitle("仓库名称1q_"+TestDataManager.getRandomIntNum(5));
			bean.setRemark("新增仓库信息_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
	
			check_verify(createIndepMchCall.getmchId());		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_createDepot_002_2() {
		Logger.start(true,"新增仓库信息-验证独立商户的代理");
		try {
			
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createIndepMchCall= GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
	        applyAgentCall applyAgentCall= GodmchManageCallService.applyAndapproveAgent(createIndepMchCall.getmchId());
            
			bean.setMchId(applyAgentCall.getAgentId());
			bean.setDepotTitle("仓库名称1q_"+TestDataManager.getRandomIntNum(5));
			bean.setRemark("新增仓库信息_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
	
			check_verify(applyAgentCall.getAgentId());		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_createDepot_002_3() {
		Logger.start(true,"新增仓库信息-验证独立商户的代理审核未通过");
		try {
			
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createIndepMchCall= GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
	      //  applyAgentCall applyAgentCall= GodmchManageCallService.applyAndapproveAgent(createIndepMchCall.getmchId());
			applyAgentBean applyBean = GodmchManageCallService.InitApplyAgentBean();
			applyBean.setMchId(createIndepMchCall.getmchId());
			applyBean.setAppKey("appsqSeller_" + createIndepMchCall.getmchId());
			applyAgentCall applyCall = GodmchManageCallService.ApplyAgentCall(applyBean);
			
            
			bean.setMchId(applyCall.getAgentId());
			bean.setDepotTitle("仓库名称1q_"+TestDataManager.getRandomIntNum(5));
			bean.setRemark("新增仓库信息_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
	
			check_verify(applyCall.getAgentId());		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_createDepot_003() {
		Logger.start(true,"新增仓库信息--验证mchid为空-返回失败");
		try {
			
			//bean.setMchId(applyCall.getAgentId());
			bean.setDepotTitle("仓库名称1q_"+TestDataManager.getRandomIntNum(5));
			bean.setRemark("新增仓库信息_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_createDepot_004() {
		Logger.start(true,"新增仓库信息--验证仓库名称为空-返回失败");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			bean.setMchId(mchId);
			//bean.setDepotTitle("仓库名称1q_"+TestDataManager.getRandomIntNum(5));
			bean.setRemark("新增仓库信息_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_createDepot_005() {
		Logger.start(true,"新增仓库信息--验证不同商户仓库名称重复-返回成功");
		try {
			String depotTitle="仓库名称"+TestDataManager.getRandomIntNum(5);
			//商户1
			Integer mchId1 = GodmchManageCallService.CreateSellerMch();
			bean.setMchId(mchId1);
			bean.setDepotTitle(depotTitle);
			bean.setRemark("新增仓库信息_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			check_verify(mchId1);
			//商户2
			Integer mchId2 = GodmchManageCallService.CreateSellerMch();
			bean.setMchId(mchId2);
			bean.setDepotTitle(depotTitle);
			bean.setRemark("新增仓库信息_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			check_verify(mchId2);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_createDepot_006() {
		Logger.start(true,"新增仓库信息--验证相同商户仓库名称重复-返回失败");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			bean.setMchId(mchId);
			bean.setDepotTitle("仓库名称1q_"+TestDataManager.getRandomIntNum(5));
			bean.setRemark("新增仓库信息_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
			call.callService();
			Logger.verifyEquals("5000", call.getStatusCode1(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_createDepot_007() {
		Logger.start(true,"新增仓库信息-验证渠道角色-买家端显示名称重复-返回失败");
		try {
			
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			bean.setMchId(mchId);
			bean.setDepotTitle("仓库名称1q_"+TestDataManager.getRandomIntNum(5));
			bean.setRemark("新增仓库信息_"+TestDataManager.getRandomIntNum(5));
			bean.setBuyerTitle("买家端显示名称_"+TestDataManager.getRandomNum(5));
			bean.setPicUrl("http://www.baidu.com_"+TestDataManager.getRandomNum(5)+".jpg");
			call.setData(bean);
			call.callService();
			
			bean.setDepotTitle("仓库名称1q_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			
			Logger.verifyEquals("5000", call.getStatusCode1(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}